package room

import (
	"gitee.com/game_diamond/consts"
	"time"
)

//executor
type StudentExecutor struct {
	StudentId int
}

func (ss *StudentExecutor) EnterAIRoom(roomId string) error {
	r, err := FindAIRoom(roomId)
	if err != nil {
		return err
	}
	return r.AddStudent(ss.StudentId)
}

type TeacherExecutor struct {
	TeacherId int
}

func (ts *TeacherExecutor) CreateAIRoom(classId, courseId, roomType int) error {
	roomMutex.Lock()
	defer roomMutex.Unlock()
	roomId := MakeRoomId(ts.TeacherId, classId, courseId, consts.RoomTypeNormal)
	if _, ok := roomList[roomId]; ok {
		return errorRoomHasExist
	}
	aiRoom := new(AiRoom)
	aiRoom.OwnerId = ts.TeacherId
	aiRoom.RoomId = roomId
	aiRoom.RoomType = roomType
	//aiRoom.CourseType = courseType
	aiRoom.CreateTime = int(time.Now().Unix())
	//init
	aiRoom.Init()

	go aiRoom.GC()

	aiRoom.AddTeacher(ts.TeacherId)
	//add room
	AddRoom(roomId, aiRoom)
	//log here open room

	return nil

}
